GBML manual / Queues

queue_peek

Reads the item at the FRONT of target WITHOUT removing it. If target is empty, returns a plain default value instead (see queue_pop's own note on what that is per type) - target is left unchanged either way.

Syntax

queue_peek(target) -> element

Arguments

NameType
targetqueue

Returns

element

Description

Reads the item at the FRONT of target WITHOUT removing it. target is left unchanged either way.

If target is empty, returns a plain default value instead - the same rule queue_pop uses (0/0.0/false/an empty string/nothing, depending on target's element type). Useful for checking who is next before actually advancing the queue.

Example

/// @type {queue<int>}
/// @capacity 4
var turn_order = [1, 2, 3];
var next_up = queue_peek(turn_order); // 1 - turn_order is still [1, 2, 3]
A real capture - the queue and FRONT shown as ? before the peekA real capture - the queue and FRONT shown as ? before the peek
A real capture - the queue and FRONT shown as ? before the peek
The same queue, unchanged - FRONT now shows 1, the value queue_peek readThe same queue, unchanged - FRONT now shows 1, the value queue_peek read
The same queue, unchanged - FRONT now shows 1, the value queue_peek read

On the GBA

the GBA module's own deque front() - O(1), guarded by an empty() check first so it is never called on an empty deque (which would be undefined behavior, not just a wrong answer).

See also: queue_popqueue_pushqueue_lengthqueue_emptyData containers